****************************
*Replication file for results in Sønderskov, K. M. (2009). Different goods, different effects: exploring the effects of generalized social trust in large-N collective action. Public Choice, 140(1-2), 145-160.
****************************

version 13
use ReplicationData01, clear
*Table 1
format %9.2f generalized_social_trust recycling organic_food_consumption 
sort generalized_social_trust
list country generalized_social_trust recycling organic_food_consumption

*Table 3 (social trust only)
*recycling
loc varlist "recycling generalized_social_trust generalized_institutional_trust  enviromental_values income_recycling urbanization gender convenience_of_recycling age ethnic_fractionalization  education"
parse "`varlist'", parse(" ")
local depvar "`1'"
mac shift
local ebavar "`1'"
mac shift
local z "`*'"
local S_nz : word count `z'
local i "1"
while "`1'" ~= "" {
	tempvar z`i'
	quietly : gen `z`i'' = `1' 
	macro shift
	local i = `i' + 1
	}

local i "1"
macro list
tempfile Rresults
tempname Rsim
postfile `Rsim' Rcoef Rbeta Rpval using `Rresults', replace
loc c = 1
while `i' <= `S_nz' { 

	local j = `i'+1
	while `j'<=`S_nz' {
	local k = `j' + 1
	while `k' <= `S_nz' {
	local i1 = `k' + 1
	while `i1' <= `S_nz' {
	reg `depvar' `ebavar' `z`i'' `z`j'' `z`k'' `z`i1'' ,r
	di `c'
	loc c = `c' +1
	mat b = e(b)
	estadd beta
	mat beta = e(beta)
	post `Rsim' (b[1,1]) (beta[1,1]) (ttail(e(df_r),_b[generalized_social_trust]/_se[generalized_social_trust])*2)


	local i1 = `i1' + 1
	}
	local k = `k' + 1
	}
	local j = `j'+ 1
	}

local i = `i' + 1

}

postclose `Rsim'
use `Rresults'
gen id = _n
save `Rresults',replace

*Organic food consumption
use ReplicationData01.dta, clear
loc varlist "organic_food_consumption generalized_social_trust generalized_institutional_trust  enviromental_values income_organic urbanization gender price_premiums age ethnic_fractionalization  education"
parse "`varlist'", parse(" ")
local depvar "`1'"
mac shift
local ebavar "`1'"
mac shift
local z "`*'"
local S_nz : word count `z'
local i "1"
while "`1'" ~= "" {
	tempvar z`i'
	quietly : gen `z`i'' = `1' 
	macro shift
	local i = `i' + 1
	}

local i "1"
macro list
tempfile Oresults
tempname Osim
postfile `Osim' Ocoef Obeta Opval using `Oresults', replace
loc c = 1
while `i' <= `S_nz' { 

	local j = `i'+1
	while `j'<=`S_nz' {
	local k = `j' + 1
	while `k' <= `S_nz' {
	local i1 = `k' + 1
	while `i1' <= `S_nz' {
	reg `depvar' `ebavar' `z`i'' `z`j'' `z`k'' `z`i1'' ,r
	di `c'
	loc c = `c' +1
	mat b = e(b)
	estadd beta
	mat beta = e(beta)
	post `Osim' (b[1,1]) (beta[1,1]) (ttail(e(df_r),abs(_b[generalized_social_trust]/_se[generalized_social_trust]))*2)


	local i1 = `i1' + 1
	}
	local k = `k' + 1
	}
	local j = `j'+ 1
	}

local i = `i' + 1

}

postclose `Osim'
use `Oresults'
gen id = _n
save `Oresults',replace

use `Rresults'
merge 1:1 id using `Oresults', nogen
drop id
format %9.2f *
su, format sep(3)

exit
